package Dao;

import Pojo.Course;
//import Pojo.SelectCoure;
import Pojo.Student;
import Utils.JDBCUtils;
import dto.StudentCourse;
import org.junit.Test;

import java.sql.Connection;
import java.util.List;

public class Courseimply extends BaseDao implements CourseDao{

    @Override
    public List<Course> selectCourseTable() {
        Connection conn = JDBCUtils.getConnection();
        String sql="select id,cname,ctime,address from course ";
        return queryForlist(Course.class, conn, sql);
    }

    @Override
    public Course selectByno(Integer id) {
        Connection conn = JDBCUtils.getConnection();
        String sql="select id,cname,ctime,address from course where id=?";
        Course course = queryOne(Course.class, conn, sql, id);
        return course;
    }

    @Override
    public void add(StudentCourse course) {
        Connection conn = JDBCUtils.getConnection();
        String sql="insert into studentcourse(cid,sid)values(?,?)";
        aduMthod(conn,sql,course.getCid(),course.getSid());

    }

    @Override
    public List<Course> selectStudentCourseTable(Integer id) {
        Connection conn = JDBCUtils.getConnection();
        String sql="SELECT course.`id`,course.`cname`,course.`ctime`,course.`address` FROM course WHERE course.`id` IN\n" +
                "(SELECT studentcourse.`cid` FROM studentcourse WHERE studentcourse.`sid`=?) ";
        return queryForlist(Course.class, conn, sql,id);
    }


//    @Override
//    public void add(SelectCoure selectCourecourse) {
//        Connection conn = JDBCUtils.getConnection();
//        String sql="insert into studentcourse(scid,scname,sctime,scaddress)values(?,?,?,?)";
//        aduMthod(conn,sql,selectCourecourse.getScid(),selectCourecourse.getScname(),selectCourecourse.getSctime(),selectCourecourse.getScaddress());
//    }
}
